<?xml version="1.0" encoding="UTF-8"?>
<!-- EXPLANATION
     This style sheet takes an instance document as an input. The instance document must have a primary taxonomy and dimension taxonomies that allow for cross-context aggregation for the rendered pivot table(s) to be meaningful.  

    Three parameters MAY be provided in the "Input Parameters" section of the transform dialog box:

       1) The role uri of the extended link. (role) http://www.xbrl.org/2003/role/link
       2) The unit of the facts. (unit) U-Monetary
       3) The language of the label. (lang) en
      
   Some input documents, such as Sales, use custom extended link roles to define the relationships between primary items and hypercubes. To render a pivot table use hypercubes defined in the http://www.SampleCompany.com/PrimaryConcepts base set, the role input parameter should be defined to have the value http://www.SampleCompany.com/PrimaryConcepts.  This value can be directly modified   
   below or in the Transformation dialog box.
-->

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xbrli="http://www.xbrl.org/2003/instance" 
    xmlns:link="http://www.xbrl.org/2003/linkbase"
    xmlns:ci="http://www.UBmatrix.com/Patterns/Sales" 
    xmlns:ubmfdt="http://www.ubmatrix.com/2005/function/dimension/taxonomy"
    xmlns:ubmfdi="http://www.ubmatrix.com/2005/function/dimension/instance"
    xmlns:ubmfi="http://www.ubmatrix.com/2005/function/instance"
    xmlns:ubmft="http://www.ubmatrix.com/2005/function/taxonomy"
    xmlns:ubmfddts="http://www.ubmatrix.com/2005/function/dimension/dts"
    xmlns:ubmfdts="http://www.ubmatrix.com/2005/function/dts">
    
    <xsl:output method="xml" indent="yes"/> 
   	<xsl:param name="role">http://www.xbrl.org/2003/role/link</xsl:param>
   	<xsl:param name="unit">U-Monetary</xsl:param>
   	<xsl:param name="lang">en</xsl:param>
        <xsl:param name="resourceRoleUri">http://www.xbrl.org/2003/role/label</xsl:param>

	<xsl:decimal-format name='base' decimal-separator='.' grouping-separator=',' minus-sign='-' />

    <xsl:template match="/">
        
        <!-- This is the instance xml node -->
        <xsl:variable name="instance" select="/xbrli:xbrl" />	
		<xsl:variable name="primaryTaxonomy" select="ubmfdi:primary-taxonomies($instance)[1]" />	
		<xsl:variable name="u" select="ubmfi:unit($instance,unit)" />
		
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
				  <link rel="stylesheet" type="text/css" href="Patterns.css"/>
			</head>
            <body>
               <center>
                    <h1>Financial highlights of each primary items in <i><xsl:value-of select="ubmfdts:where-is($primaryTaxonomy)" /></i>.</h1>
                <p/>

					<xsl:variable name="primaryItems" select="ubmfdt:primary-items($primaryTaxonomy)" />

					<!-- Loop over each primary item in the primary taxonomy. A primary item is an item concept that has one or more has-hypercube 
						  relationships connecting it to a hypercube -->
					<xsl:for-each select="$primaryItems">
							<xsl:variable name="primaryItem" select="." />		
					
						  <table width='600' border='0' cellpadding='0' cellspacing='0'>
							 <col width='600'/>
							 <tr>
								  <td  class='Heading'><xsl:value-of select="ubmft:label($primaryItem,$lang,$resourceRoleUri)" /></td>
						    </tr>
   	
							 <tr>
							   <td>

							     <table  width='600' border='0' cellpadding='0' cellspacing='0'>
									  <col width='500' />
									  <col width='100' />
									  <col width='100' />
									  <col width='100' />

									 <!-- These columns should not be hard coded -->	
									 <tr>
										 <td colspan='1' class='ColumnHeading-nl'> </td>
										 <td colspan='1' class='ColumnHeading-nl'>2003</td>
										 <td colspan='1' class='ColumnHeading-nl'>2002</td>
										 <td colspan='1' class='ColumnHeading-nl'>2001</td>
									  </tr>
									  <tr>
										 <td colspan='1' class='ColumnHeading'> </td>
										 <td colspan='1' class='ColumnHeading'>&#8364;' 000</td>
										 <td colspan='1' class='ColumnHeading'>&#8364;' 000</td>
										 <td colspan='1' class='ColumnHeading'>&#8364;' 000</td>
									  </tr>        
									  <tr class='Blank'>
										 <td colspan='4' class='Blank'>-</td>
									  </tr>

									<!-- Loop over every dimension connected to a primary item. The set of dimensions may be 
									  contained in one or more hypercubes -->
									<xsl:for-each select="ubmfdt:dimensions(., $role, null)" >

											<xsl:variable name="dimension" select="." />
							
											<tr class="SubSection">
												<td class="SubSectionHeading">
													<i><xsl:value-of select="ubmft:label($dimension, $lang, $resourceRoleUri)" /></i>
												</td>
											</tr>
											
											<!-- Loop over all aggregators within a dimension -->
											<xsl:for-each select="ubmfdt:aggregators($primaryItem, $role, null, $dimension)">
											    
													<xsl:variable name="aggregator" select="." />

													<!-- loop over each aggregator contributor in the veritical direction -->
													<xsl:for-each select="ubmfdt:aggregator-contributors($primaryItem, $aggregator, $role, null, $dimension)">													
														<xsl:variable name="aggregatorContributor" select="." />
				
														<tr>
															<td class="Label">
																&#160;&#160;<xsl:value-of select="ubmft:label($aggregatorContributor,$lang, $resourceRoleUri)" />
															</td>

														<xsl:variable name="discoverables" select="ubmfdi:discoverables($primaryItem, $role, null, $dimension, $aggregator, $u)" />
														<!-- loop over each discoverable fact the first time to find and render the contributor facts -->
														<xsl:for-each select="$discoverables" >

																<xsl:variable name="discoverableFact" select="." />
				
																<!-- loop over all contributors of the discoverable fact -->
																<xsl:for-each select="ubmfdi:contributors($discoverableFact, $role, null, $dimension, $aggregatorContributor)">
																	<xsl:variable name="contributorFact" select="." />

																	<td class="Value">
																		<xsl:value-of select="format-number($contributorFact div 1000,'#,##0','base')" />
																	</td>
															
																</xsl:for-each> <!-- contributors -->														
														</xsl:for-each> <!-- discoverables -->
														
													</tr>
														
												</xsl:for-each> <!-- aggregator-contributors -->
											
												<tr class="Line"	>
														<td class="Label-r">
															<xsl:value-of select="ubmft:label($aggregator,$lang,$resourceRoleUri)" />&#160;&#160;
														</td>

														<xsl:variable name="discoverables" select="ubmfdi:discoverables($primaryItem, $role, null, $dimension, $aggregator, $u)" />

														<!-- loop over each discoverable fact again in the horizontal position to report the aggregated fact values -->
														<xsl:for-each select="$discoverables" >

																<xsl:variable name="discoverableFact" select="." />	

																<td class="ValueLineOverUnder">
																	<xsl:value-of select="format-number($discoverableFact div 1000,'#,##0','base')" />
																</td>
														
														</xsl:for-each>	<!-- discoverable -->
		
												 </tr>					
														
											</xsl:for-each> <!-- aggregator -->
									
									</xsl:for-each>	<!-- dimension -->

								  </table>
								 </td>
							   </tr>
							</table>
						</xsl:for-each>	<!-- primary items -->	
                  </center>
           </body>
        </html>
    </xsl:template>
</xsl:stylesheet>
                        